home *** CD-ROM | disk | FTP | other *** search
/ Power CD / Power CD ATARI-Rechner Lieben.iso / SPEZIAL / GEMVIEW / VERSION.3 / MODULS.SRC / LOADMODL / IMAGELAB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-30  |  2.9 KB  |  110 lines

  1. /* imagelab.c
  2.  *
  3.  * dieter fiebelkorn 24.08.91
  4.  *
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include <math.h>
  12. #include <vdi.h>
  13. #include <aes.h>
  14. #include "image.h"
  15. #include "imageopt.h"
  16. #include "module.h"
  17.  
  18.  
  19.  
  20. int imagelabIdent(LOAD_Structure *loadS, unsigned int verbose)
  21. {
  22.   ZFILE   *zf;
  23.   char     header[10];
  24.   int      r, w, h;
  25.   int      colors;
  26.   char    *fullname = loadS->in_filename;
  27.  
  28.   if (! (zf= (*loadS->input.open)(fullname, 0x00))) {
  29.     (*loadS->error.printerr)("  Error reading ImageLab!");
  30.     return(0);
  31.   }
  32.   switch ((int)(*loadS->input.read)(zf, header, 10UL)) {
  33.     case 10:
  34.       if (strncmp(header, "B&W256", 6) == 0) {
  35.         w = *((unsigned short*)&header[6]);
  36.         h = *((unsigned short*)&header[8]);
  37.         colors = 256;
  38.         (*loadS->print.printout)("%s\n  is a %dx%d Imagelab picture\n",fullname , w, h);
  39.         r = 1;
  40.         break;
  41.       }
  42.       if ((*(long*)header == 0x0F0F0001L) && (*(short*)&header[8] == 0x0001)) {
  43.         w = *((unsigned short*)&header[4]);
  44.         h = *((unsigned short*)&header[6]);
  45.         colors = 256;
  46.         (*loadS->print.printout)("%s\n  is a %dx%d Videodigitizer picture\n",fullname , w, h, colors);
  47.         r = 1;
  48.         break;
  49.       }
  50.       r= 0;
  51.       break;
  52.  
  53.     default:
  54.       r= 0;
  55.       break;
  56.   }
  57.   (*loadS->input.close)(zf);
  58.   return(r);
  59. }
  60.  
  61.  
  62.  
  63. Image *imagelabLoad(LOAD_Structure *loadS, unsigned int verbose)
  64.   ZFILE         *zf;
  65.   Image         *image;
  66.   unsigned char  header[12];
  67.   int            w, h, planes, colors, i, j, id;
  68.   char          *fullname = loadS->in_filename;
  69.   int            id_only  = loadS->identify_only;
  70.   
  71.   id = imagelabIdent(loadS, verbose);
  72.   if (id_only)
  73.     return((Image*)id);
  74.   if (id == 0)
  75.     return(NULL);
  76.  
  77.   zf= (*loadS->input.open)(fullname, 0x00);
  78.   (*loadS->input.read)(zf, header, 10UL);
  79.   if (strncmp(header, "B&W256", 6) == 0) {
  80.     w = *((unsigned short*)&header[6]);
  81.     h = *((unsigned short*)&header[8]);
  82.   } else {
  83.     w = *((unsigned short*)&header[4]);
  84.     h = *((unsigned short*)&header[6]);
  85.   }
  86.   planes = 8;
  87.   colors = 256;
  88.  
  89.   image= (*loadS->images.newRGBImage)(NULL, (unsigned int) w, (unsigned int) h, planes);
  90.   if (!image) {
  91.     (*loadS->input.close)(zf);
  92.     return (image);
  93.   }
  94.  
  95.   if ((*loadS->input.read)(zf, image->data, (unsigned long)w * (unsigned long)h) != (unsigned long)w * (unsigned long)h)
  96.     (*loadS->print.printout)("  Bad read on image data\n");
  97.  
  98.   for (i= 0, j = colors - 1; i < colors; i++, j--) {
  99.     image->rgb.red[i]   = (unsigned int) ( ((unsigned long) (255-j)) << 8);
  100.     image->rgb.green[i] = (unsigned int) ( ((unsigned long) (255-j)) << 8);
  101.     image->rgb.blue[i]  = (unsigned int) ( ((unsigned long) (255-j)) << 8);
  102.   }
  103.   image->rgb.used = 256;
  104.   image->title= DupString(loadS, fullname);
  105.  
  106.   (*loadS->input.close)(zf);
  107.   return (image);
  108. }
  109.